package com.ruoyi.web.controller.aggregation;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.aggregation.dto.PageDTO;
import com.ruoyi.system.domain.aggregation.Withdraw;
import com.ruoyi.system.service.aggregation.IWithdrawService;

/**
 * 提现Controller
 * 
 * @author ruoyi
 * @date 2025-01-01
 */
@RestController
@RequestMapping("/agg/withdraw")
public class WithdrawController
{
    @Autowired
    private IWithdrawService withdrawService;

    /**
     * 提现列表
     */
    @PostMapping("/page")
    public AjaxResult page(@RequestBody PageDTO pageDTO)
    {
        try
        {
            PageHelper.startPage(pageDTO.getPageIndex().intValue(), pageDTO.getPageSize().intValue());
            Withdraw query = new Withdraw();
            List<Withdraw> list = withdrawService.selectWithdrawList(query);
            PageInfo<Withdraw> pageInfo = new PageInfo<>(list);
            return AjaxResult.success(pageInfo);
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 提现申请
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestParam Long userId, 
                         @RequestParam Integer userType,
                         @RequestParam Long amount)
    {
        try
        {
            withdrawService.applyWithdraw(userId, userType, amount);
            return AjaxResult.success();
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 提现审核
     */
    @PostMapping("/check")
    public AjaxResult check(@RequestParam Long id, 
                           @RequestParam Integer statue,
                           @RequestParam(required = false) String reason)
    {
        try
        {
            withdrawService.checkWithdraw(id, statue, reason);
            return AjaxResult.success();
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 提现详情
     */
    @GetMapping("/getInfo")
    public AjaxResult getInfo(@RequestParam Long id)
    {
        try
        {
            Withdraw withdraw = withdrawService.selectWithdrawById(id);
            return AjaxResult.success(withdraw);
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }
}

